<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>我的地址</title>
    <!--<link rel="stylesheet" href="../css/common.css">-->
    <!--<link rel="stylesheet" href="../css/page.css">-->
    <link rel="stylesheet" href="../css/base.css">
    <script src="../js/jquery-3.2.1.min.js"></script>
    <script src="../js/public.js"></script>

    <!--<script src="../js/media.js"></script>-->
    <script src="../js/common.js"></script>
    <style>
        .add_price {
            position: fixed;
            bottom: 0;
            left: 0;
            right: 0;
            height: .66rem;
            background: #fff;
        }

        .add_price .left {
            font-size: 12px;
            padding-left: .12rem;
            box-sizing: border-box;
            line-height: .66rem;
        }

        .add_price .left font {
            color: red;
            display:inline-block;
            width:3rem;
        }

        .add_price .right {
            float: right;
            width: 2.27rem;
            height: .66rem;
            line-height: .66rem;
            background: rgba(95, 49, 4, 1);
            color: #fff;
            font-size: 14px;
            text-align: center;
        }

        .list{overflow: hidden;border-bottom: 1px solid #f2f2f2;padding: .2rem;box-sizing: border-box;}
        .list-fl{
            float: left;
            width: 15%;
            text-align: left;
        }
        .list-fl>img{
            width: .4rem;
            margin: .2rem 0;
        }
        .list-mid{
            width:75%;
            float: left;
        }
        .list-ri{
            width: 10%;
            float: left;
        }
        .list-ri>a>img{
            width: .34rem;
            margin: .2rem 0;
        }
        .name{
            font-size: 14px;
        }
        .address{
            font-size: 12px;
        }
        .add-img{
            width: .20px;
            height: 20px;
            position: absolute;
            top: 10px;
        }
        .add-font{
            font-size: 12px;
            text-align: center;
        }
        .div-add{
            height: 40px;
            line-height: 40px;
            width: 80%;
            margin: 10px auto;
            text-align: center;
        }
    </style>
</head>

<body>
<!--    &lt;!&ndash;头部&ndash;&gt;
    <div class="public-header flex">
        &lt;!&ndash;<span class="public-header-left-search"></span>&ndash;&gt;
        <span class="public-header-left-back"></span>
        <span class="public-header-center">我的地址</span>
        <span class="public-header-right">完成</span>
    </div>-->

    <!--正文-->
    <div class="my-address bc-gray">
        <ul>
            <!--<li class="flex" v-for="item in datas">-->
                <!--<span :class="{active:item.selec}" :data-add='item.addId' @click='save_address(this)'></span>-->
                <!--<div>-->
                    <!--<p class="p1">{{item.name}}</p>-->
                    <!--<p class="p2">{{item.addDesc}}</p>-->
                <!--</div>-->
                <!--<em></em>-->
            <!--</li>-->
        </ul>
        <div id="main">
        </div>
        <p class="tip flex" style="line-height: .88rem;background: #fff;padding: 0 .2rem;position: relative;" onclick='javascript:window.location.href="personaladdress.html"'>
            <img src="../img/添加@2x.png" style="width: 20px;height: 20px;vertical-align: middle;">
            <span class="p2" style="vertical-align: middle;">添加地址</span>
            <img src="../img/下一步@2x.png" style="width: 9px;position: absolute;right: 0;top: .32rem;right: .2rem;">
        </p>
        <p class="tip flex cou" style="line-height: .88rem;background: #fff;padding: 0 .2rem;position: relative;">
            <img src="../img/添加@2x.png" style="width: 20px;height: 20px;vertical-align: middle;">
            <span class="p2" style="vertical-align: middle;">优惠券</span>
            <span class="coupon p2" style="vertical-align: middle;float: right;color:red;margin-right: 15px;"></span>
            <img src="../img/下一步@2x.png" style="width: 9px;position: absolute;right: 0;top: .32rem;right: .2rem;">
        </p>
        <p class="add_price">
            <span class="left" >合计:￥<font id="price"></font></span>
            <span class="right" style="display:none"  id="tijiao" onclick="tjOrder()">提交订单</span>
            <span class="right" style="display:none;" id="xiayibu" onclick="xyb()">下一步</span>
        </p>
    </div>
    <script src='../js/vue.js'></script>
    <script src='../js/vue-resource.min.js'></script>
    <script>
        var addressId = '';
        var coupon_id = GetQueryString("coupon_id");
        var auction_id = GetQueryString("auction_id");
        //var price = GetQueryString("produce_unit_price") ==null ? GetQueryString("price"):GetQueryString("produce_unit_price");
        if(GetQueryString("produce_unit_price") ==null || GetQueryString("produce_unit_price") ==0){
        	var price = GetQueryString("price");
        }else{
        	var price = GetQueryString("produce_unit_price");
        }
        var or = GetQueryString("order");
        var produce_con = GetQueryString("produce_con");//购买的数量
        var produce_rate = GetQueryString("produce_rate");//店铺折扣
        var all_price = (price*produce_con).toFixed(2);//没有满减的总价格
        var customization_msg = sessionStorage.dingInf;
        var customization_describe = sessionStorage.miaoInf;
        var reducePrice = parseFloat(GetQueryString("reducePrice"));//订单优惠的价格
        var order_num = GetQueryString("order_num");//订单编号，只有在待付款中的才有这个字段
	    if(reducePrice){//检测是否存在优惠，如果没有这个字段表示不存在优惠
	    	$('.coupon').html('-￥'+reducePrice)
	    	var all_price = (all_price-reducePrice).toFixed(2);
	    	$("#price").text(price+' * '+produce_con+' - '+reducePrice+' =￥'+all_price);
	    }else{
	    	$("#price").text(price+' * '+produce_con+' =￥'+all_price);
	    }
        //console.log("商品单价："+price+"商品数量："+produce_con+" 商品总价："+all_price);
        $(function () {
            //强制刷新当前页面解决ios当前页面不刷新问题
            var isPageHide = false;
            window.addEventListener('pageshow', function () {
                if (isPageHide) {
                    window.location.reload();
                }
            });
            window.addEventListener('pagehide', function () {
                isPageHide = true;
            });
            if(or == 1){
                $("#xiayibu").show();
            }else{
                $("#tijiao").show();
            };
            $('.cou').click(function(){//跳转到优惠券的页面
            	//console.log("price="+price);
				window.location.href='coupon.html?order_num='+order_num+'&orderType='+'2'+'&price='+price+"&auction_id="+auction_id+"&order="+or+"&produce_con="+produce_con+
				"&produce_rate="+produce_rate+"&produceid="+GetQueryString("produceid")+"&storeId="+GetQueryString("storeId")+"&auction_id="+auction_id+"&oid="+GetQueryString('oid');
			})
        })
        var addressId = '';
        $(function (){
            var uid = sessionStorage.getItem("uid");
            $.ajax({//获取地址列表
                url:base_url+"ZITAOHUI/address/list",
                data:{
                    uid:uid
                },
                dataType:"json",
                success:function (data){
                    console.log(data);
                    if(data.code == 1){
                        var _d = data.extend.data;
                        if(_d.length == 0) {
                            $("#main").html('<div>'+"暂无地址"+'</div>')
                        }else{
                            $.each(_d,function(k,v){
                                $("#main").append('  <div class="list">' +
                                    '        <div class="list-fl" on="0" data-id="'+v.addId+'">' +
                                    '            <img src="../img/allchoose.png" >' +
                                    '        </div>'+
                                    '        <div class="list-mid">' +
                                    '            <p class="name">'+'<span>'+v.name+'</span>'+ '<span>'+v.phone+'</span>' +'</p>' +
                                    '            <p class="address">'+v.addDesc+'</p>' +
                                    '        </div>' +
                                    '        <div class="list-ri">' +
                                    //                                '<a href='+"personaladdress.html?id="+v.addId+"&postCode="+v.postCode+'>'+
                                    //                                '            <img src="../img/编辑@2x.png">' +
                                    //                                '</a>'+
                                    '        </div>' +
                                    '    </div>')
                            })
                        }
                    }else{
                        alert(data.msg);
                    }
                },
                error:function (error){

                }
            });

            $("#main").on('click','.list-fl',function (){
                var _id = $(this).attr("data-id");
                $('.list-fl').find('img').attr('src',"../img/allchoose.png");
                $(this).find('img').attr("src","../img/allchooseon.png");
                addressId = _id;
            })
        });
        function tjOrder (){//提交订单的函数
            console.log("提交订单");
            if(isNull(addressId)){
                alert("请选择地址");
                return false;
            }
            $.ajax({
                url: base_url + 'ZITAOHUI/place/order',
                data: {
                    addressId: addressId,
                    orderTotalPrice:all_price,
                    produceCon:produce_con,
                    userTo:sessionStorage.getItem("uid"),
                    storeId:GetQueryString("storeId"),
                    produceId:GetQueryString("produceid"),
                    produce_unit_price:price,
                    auction_id:auction_id,
                    customization_msg:customization_msg,//私人定制信息
                    customization_describe:customization_describe,//私人定制描述
                    user_coupon_id:GetQueryString("user_coupon_id")
                },
                success: function (data) {
                    //console.log(data)
                    if (data.code == 1) {
                        window.location.href = 'userPay.html?num='+data.extend.data+"&orderType=2&price="+all_price+"&coupon_id="+coupon_id+"&auction_id="+auction_id;
                    }
                }
            })
        }
        function xyb (){//在待付款中的选择
            var oid = GetQueryString('oid');
            if(isNull(addressId)){
                alert("请选择地址");
                return false;
            }
            $.ajax({
                url: base_url + 'ZITAOHUI/updateOrderAddress',
                data: {
                    addid:addressId,
                    orderid:oid
                },
                success: function (data) {
                    console.log(data)
                    if (data.code == 1) {
                        window.location.href = 'userPay.html?num='+oid+"&orderType=2&price="+all_price+"&order_num="+order_num+"&auction_id="+auction_id;
                    }
                }
            })
        }
    </script>

</body>

</html>